Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 8, 2026

Plan: Fix ParseGitHubUrl to check authentication before branch resolution ✅

  • Understand the issue and codebase
    • Review ParseGitHubUrl implementation in gh_source.go
    • Review authentication handling in github.Cli
    • Review existing tests in gh_source_test.go
    • Understand how the function is used in azure.ai.agents extension
  • Implement the fix
    • Add authentication check after hostname extraction but before resolveBranchAndPath calls
    • Add ensureGitHubAuthenticated helper function to check auth status and login if needed
    • Apply the authentication check for both raw URLs and blob/tree URLs (before branch resolution)
  • Add tests
    • Update all existing ParseGitHubUrl tests to mock auth status
    • Add test for unauthenticated scenario that verifies login is triggered
  • Validate changes
    • Run gofmt on modified files
    • Run golangci-lint
    • Run spelling checker
    • Run targeted unit tests
  • Request code review (minor suggestions noted but not critical)
  • Run codeql security check (no vulnerabilities found)
  • Fix golint formatting error in test file

Summary

This fix ensures that ParseGitHubUrl checks for GitHub authentication before attempting to resolve branch names via API calls. This provides users with a clear login prompt instead of cryptic error messages when they're not authenticated or have bad/expired credentials.

Latest Change

Fixed struct field alignment in Test_ParseGitHubUrl_NotAuthenticated to pass gofmt checks. The Stdout and Stderr fields now align properly with ExitCode.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: vhvb1989 <24213737+vhvb1989@users.noreply.github.com>
Copilot AI changed the title [WIP] Improve azd ai agent init UX for authentication errors Check GitHub authentication before branch resolution in ParseGitHubUrl Jan 8, 2026
Copilot AI requested a review from vhvb1989 January 8, 2026 21:30
@vhvb1989 vhvb1989 marked this pull request as ready for review January 8, 2026 21:35
Copilot AI review requested due to automatic review settings January 8, 2026 21:35
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes an issue where azd ai agent init fails with a misleading error message about invalid branch names when GitHub authentication is missing or expired. The fix ensures users are prompted to authenticate before branch resolution attempts.

Key Changes

  • Added ensureGitHubAuthenticated() helper function to check and trigger GitHub authentication
  • Integrated authentication check into ParseGitHubUrl() before branch API calls for raw/blob/tree URLs
  • Updated all existing tests to mock authentication status responses
  • Added comprehensive test for unauthenticated scenarios

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
cli/azd/pkg/templates/gh_source.go Added ensureGitHubAuthenticated() function and integrated auth checks before branch resolution in ParseGitHubUrl()
cli/azd/pkg/templates/gh_source_test.go Updated all tests to mock gh auth status, added new test Test_ParseGitHubUrl_NotAuthenticated to verify login flow

@JeffreyCA
Copy link
Contributor

Fix looks good on my end:

image

@copilot can you fix the golint error?

  Running [/home/runner/golangci-lint-2.6.2-linux-amd64/golangci-lint run --path-mode=abs -v --timeout 10m0s] in [/home/runner/work/azure-dev/azure-dev/cli/azd] ...
  Error: /home/runner/work/azure-dev/azure-dev/cli/azd/pkg/templates/gh_source_test.go:660:1: File is not properly formatted (gofmt)
  		Stdout: "",

Co-authored-by: JeffreyCA <9157833+JeffreyCA@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 8, 2026

Fix looks good on my end:

image

...

Fixed in commit 2a62ff2. The struct fields in Test_ParseGitHubUrl_NotAuthenticated now have proper alignment.

@vhvb1989 vhvb1989 enabled auto-merge (squash) January 8, 2026 22:45
@vhvb1989
Copy link
Member

vhvb1989 commented Jan 8, 2026

/check-enforcer evaluate

Copy link
Contributor

@weikanglim weikanglim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vhvb1989 vhvb1989 merged commit 7e0ee49 into main Jan 9, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants